<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <th:block th:include="views/include :: header('添加项目')"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <style>
        .layui-form-item  layui-input-block {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">项目名称</label>
                <div class="layui-input-block">
                    <input type="text" name="proName" lay-verify="required" lay-reqtext="项目名称不能为空" placeholder="请输入项目名称"  value="" class="layui-input">
<!--                    <tip>填写自己管理账号的名称。</tip>-->
                </div>
            </div>
         <!--   <div class="layui-form-item">
                <label class="layui-form-label required">手机</label>
                <div class="layui-input-block">
                    <input type="number" name="phone" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="email" name="email"  placeholder="请输入邮箱"  value="" class="layui-input">
                </div>
            </div>-->
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">项目描述</label>
                <div class="layui-input-block">
                    <textarea name="despection" class="layui-textarea" placeholder="请输入描述信息"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="isPub" lay-filter="sm" value="1" title="公开项目" checked>
                    <input type="radio" name="isPub" lay-filter="sm" value="0" title="私密项目" >
                </div>
            </div>
            <div class="layui-form-item layui-form-text" id="pwd">
                <label class="layui-form-label">访问密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password"  placeholder="请输入访问密码"  value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','layuimini'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            layuimini = layui.layuimini;

        $("#pwd").hide();
        form.on('radio(sm)', function(data){
            // console.log(data.elem); //得到radio原始DOM对象
            // console.log(data.value); //被点击的radio的value值
            if (data.value==0){
                $("#pwd").show();
            }
            if (data.value==1){
                $("#pwd").hide();
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
                console.log(data);
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                $.ajax({
                    url: "/project/addOrUpdate",
                    data: data.field,
                    type: "post",
                    //4.接收后台修改响应回来的数据；关闭弹出层、提示修改信息、刷新table
                    success: function (data) {
                        if (data.code==0){
                            layer.msg(data.msg, {
                                offset: '15px',
                                icon: 6,
                                time: 2000
                            }, function(){
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                        }else {
                            layer.msg(data.msg, {
                                icon: 5,
                                time: 2000
                            });
                        }

                        //确认框关闭掉
                        layer.close(index);
                    }
                });
                return false;//阻止跳转；
            });


            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //     layer.close(index);
            //     // layuimini.closeCurrentTab();
            // });
            // return false;
    });
</script>
</body>
</html>